import logging
import os
from datetime import datetime

# 创建日志目录
log_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs')
os.makedirs(log_dir, exist_ok=True)

# 配置日志格式
log_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# 创建文件处理器
log_file = os.path.join(log_dir, f'app_{datetime.now().strftime("%Y%m%d")}.log')
file_handler = logging.FileHandler(log_file, encoding='utf-8')
file_handler.setFormatter(log_format)

# 创建控制台处理器
console_handler = logging.StreamHandler()
console_handler.setFormatter(log_format)

# 创建日志记录器
logger = logging.getLogger('AppLogger')
logger.setLevel(logging.DEBUG)
logger.addHandler(file_handler)
logger.addHandler(console_handler)

# 日志工具类
class AntLogger:
    @staticmethod
    def debug(message):
        logger.debug(message)
    
    @staticmethod
    def info(message):
        logger.info(message)
    
    @staticmethod
    def warning(message):
        logger.warning(message)
    
    @staticmethod
    def error(message):
        logger.error(message)
    
    @staticmethod
    def critical(message):
        logger.critical(message)